$(document).ready(function(){
    var sendCode = $("#sendCode");
    var mobile = $("#memberAccount");
    var bind = $("#submitBind");
    function showMessage(message) {
        $('#message').html(message.message||message);
    }
    sendCode.on('click', function (e) {
    	var url = '/stores/'+$('#storeId').val()+'/member-bind/send-sms';
    	$.post(url, {account: mobile.val()}, function (value, status) {
    		if (status != 'success') {
    			showMessage("获取动态登录密码错误");
    			return
    		}
    		if (value.code == 'is_not_mobile') {
    			showMessage('请输入正确的手机号');
    			return
    		}
    		showMessage(value);
    	});
    });
    
    bind.on('click', function (e) {
        var url = '/stores/'+$('#storeId').val()+'/member-bind/bind';
        $.post(url, {sns:$('#sns').val(), code:$('#code').val(),account:mobile.val(), verficationCode:$('#verficationCode').val()}, function(value, status){
            if (value.error) {
                showMessage(value.error.message);
                setTimeout(function(){
                    $('#verficationCode').focus();
                    $('#verficationCode')[0].select();
                }, 0);
                return ;
            }
            window.location.href=$('#back').val();
        });
    })
    
});
